using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace ConsoleApplication2.Models.Mapping
{
    public class FacatMap : EntityTypeConfiguration<Facat>
    {
        public FacatMap()
        {
            // Primary Key
            this.HasKey(t => t.CATEGORY);

            // Properties
            this.Property(t => t.METHOD)
                .IsRequired()
                .HasMaxLength(1);

            this.Property(t => t.TABLE)
                .HasMaxLength(15);

            this.Property(t => t.DEPRACCT)
                .IsRequired()
                .HasMaxLength(40);

            this.Property(t => t.DEPREXP)
                .IsRequired()
                .HasMaxLength(40);

            this.Property(t => t.DESC)
                .IsRequired()
                .HasMaxLength(20);

            this.Property(t => t.File_Primary_Key)
                .HasMaxLength(10);

            // Table & Column Mappings
            this.ToTable("Facat");
            this.Property(t => t.CATEGORY).HasColumnName("CATEGORY");
            this.Property(t => t.LIFE).HasColumnName("LIFE");
            this.Property(t => t.METHOD).HasColumnName("METHOD");
            this.Property(t => t.TABLE).HasColumnName("TABLE");
            this.Property(t => t.DEPRACCT).HasColumnName("DEPRACCT");
            this.Property(t => t.DEPREXP).HasColumnName("DEPREXP");
            this.Property(t => t.DESC).HasColumnName("DESC");
            this.Property(t => t.File_Primary_Key).HasColumnName("File Primary Key");
            this.Property(t => t.Note).HasColumnName("Note");

            // Relationships
            this.HasRequired(t => t.Acct)
                .WithMany(t => t.Facats)
                .HasForeignKey(d => d.DEPRACCT);
            this.HasRequired(t => t.Acct1)
                .WithMany(t => t.Facats1)
                .HasForeignKey(d => d.DEPREXP);
            this.HasOptional(t => t.Fatable)
                .WithMany(t => t.Facats)
                .HasForeignKey(d => d.TABLE);

        }
    }
}
